/*
weixin.setShare(param);
initShare();
*/
if (typeof (configData) == 'undefined' || configData == null) {
    var configData = '';

}


//配置
wx.config({
    debug: configData.debug,
    appId: configData.appId,
    timestamp: configData.timestamp,
    nonceStr: configData.nonceStr,
    signature: configData.signature,
    jsApiList: configData.jsApiList

});


(function () {

    //var para = {};


    window.initShare = function (title, content, imgUrl, detailUrl, appId, reportfunc) {
        var data = '';
        //wx.ready(function () {
        //$('footer').before('<p style="line-height:1.2;">initShare：调用</p>');
        if (typeof reportfunc != 'undefined') {
            data = {
                title: title, desc: content, link: detailUrl, imgUrl: imgUrl, success: reportfunc.success, cancel: reportfunc.cancel
            };
        } else {
            data = {
                title: title, desc: content, link: detailUrl, imgUrl: imgUrl
            };
        }
        //weixin.setShare(data);
        //para = data;
        //微信接口准备成功
        setShare(data);
        //})
    };

    //微信API
    window.weixin =
    {
        setShare: function (data) {
            para = data;
            setShare();
        }
    };


    var setShare = function (para) {
        wx.ready(function () {
            //wx.hideAllNonBaseMenuItem();
            //wx.hideMenuItems({
            //    menuList: ["menuItem:share:appMessage", //发送给朋友
            //                "menuItem:share:timeline",  //分享到朋友圈
            //                "menuItem:share:qq",        //分享到QQ
            //                "menuItem:favorite",        //收藏
            //                "menuItem:copyUrl",         //复制链接
            //                "menuItem:openWithSafari",  //在浏览器中打开
            //                "menuItem:share:email",     //发送邮件
            //                "menuItem:readMode"         //优化阅读
            //    ] // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
            //});
            //$('footer').before('<p style="line-height:1.2;">微信wx.ready--para.desc：' + para.desc + '----para.imgUrl：' + para.imgUrl + '----para.title：' + para.title + '</p>');
            //window.initShare(para.title, para.desc, para.link, para.imgUrl);
            if (!para.desc) {
                para.desc = document.title;
            }
            if (!para.imgUrl) {
                para.imgUrl = document.getElementsByTagName("img")[0].src;
            }
            //if (para.toFriendSuccess)
            //{
            //    para.success = para.toFriendSuccess;
            //}

            //分享给朋友
            var para1 = clone(para);
            //if (para1.toFriendCancel)
            //{
            //    para1.success = para.toFriendSuccess;
            //}
            //if (para1.toFriendCancel)
            //{
            //    para1.cancel = para.toFriendCancel;
            //}
            //para1.property = {
            //    success: function ()
            //    {

            //    },
            //    cancel: function ()
            //    {

            //    }
            //}
            try {
                wx.onMenuShareAppMessage(para1);

                //分享到朋友圈
                var para2 = clone(para);
                if (para2.toFriendCancel) {
                    para2.success = para.toTimelineSuccess;
                }
                if (para2.toFriendCancel) {
                    para2.cancel = para.toTimelineCancel;
                }
                wx.onMenuShareTimeline(para2);

                //分享到QQ
                var para3 = clone(para);
                if (para3.toFriendCancel) {
                    para3.success = para.toQQSuccess;
                }
                if (para3.toFriendCancel) {
                    para3.cancel = para.toQQCancel;
                }
                wx.onMenuShareQQ(para3);

            } catch (e) {
                alert(e);
            }

        })
    };

    function clone(obj) {
        function Clone() { }
        Clone.prototype = obj;
        var o = new Clone();
        for (var a in o) {
            if (typeof o[a] == "object") {
                o[a] = clone3(o[a]);
            }
        }
        return o;
    }

})();
